package com.cntcdt.api.db.dao;

import java.util.Date;
import java.util.List;

import com.cntcdt.api.db.dao.base.UpdateTaskDaoBase;
import com.cntcdt.api.db.model.UpdateTaskModel;

/**
 * 这是cdt_update_task的Dao实现类
 */
public class UpdateTaskDao extends UpdateTaskDaoBase   {
    /**
     * UpdateTaskDao对象
     */
    private static UpdateTaskDao instance = new UpdateTaskDao();

    /**
     * 默认构造方法
     */
    private UpdateTaskDao() {
    }

    /**
     * 获得对象实例
     */
    public static UpdateTaskDao getInstance() { 
         return instance;
    } 
    
    public UpdateTaskModel findByVersionIdAndPackageId(int versionId) {
        String sql = "SELECT * FROM " + TABLE + " WHERE versionId = ? and opStatus = 0 ";
       Object[] paramObjs = {versionId};
       List<UpdateTaskModel > modelList = this.queryModelList(sql, paramObjs);
       if(modelList != null && modelList.size() > 0){ 
             return  modelList.get(0);
       } 
       return null;
   }
    
    public UpdateTaskModel findByVersionIdAndPackageIdAndNoGet(int versionId) {
        String sql = "SELECT * FROM " + TABLE + " WHERE versionId = ? and opStatus = 0 and updateType = 1";
       Object[] paramObjs = {versionId};
       List<UpdateTaskModel > modelList = this.queryModelList(sql, paramObjs);
       if(modelList != null && modelList.size() > 0){ 
             return  modelList.get(0);
       } 
       return null;
   }
    
    public List<UpdateTaskModel> find30MinuteNotGetTask() {
       Date searchTime = new Date(System.currentTimeMillis()-(30*60*1000));
       System.out.println(searchTime);
       String sql = "SELECT * FROM " + TABLE + " WHERE addTime <= ? and opStatus = 0 and updateType = 1";
       Object[] paramObjs = {searchTime};
       List<UpdateTaskModel > modelList = this.queryModelList(sql, paramObjs);
       return modelList;
   }
    
    
    
    public List<UpdateTaskModel> find24HNotGetTask() {
       Date searchTime = new Date(System.currentTimeMillis()-(24*60*60*1000));
       System.out.println(searchTime);
       String sql = "SELECT * FROM " + TABLE + " WHERE addTime <= ? and opStatus = 0 and updateType = 1";
       Object[] paramObjs = {searchTime};
       List<UpdateTaskModel > modelList = this.queryModelList(sql, paramObjs);
       return modelList;
   }
}
